/*     */ package net.sourceforge.appgen.model;
/*     */ 
/*     */ import java.io.Serializable;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import net.sourceforge.appgen.converter.FirstCharacterLowerCaseConverter;
/*     */ import net.sourceforge.appgen.converter.StringConverter;
/*     */ import net.sourceforge.appgen.util.ConventionUtils;
/*     */ import net.sourceforge.appgen.util.FileUtils;
/*     */ 
/*     */ public class Dao
/*     */   implements Serializable
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  35 */   private static final StringConverter firstCharacterLowerCaseConverter = new FirstCharacterLowerCaseConverter();
/*     */   private Entity entity;
/*     */ 
/*     */   public Dao(Entity entity)
/*     */   {
/*  40 */     this.entity = entity;
/*     */   }
/*     */ 
/*     */   public String getInterfaceName() {
/*  44 */     return this.entity.getClassName() + "Dao";
/*     */   }
/*     */ 
/*     */   public String getClassName() {
/*  48 */     return getInterfaceName() + "Impl";
/*     */   }
/*     */ 
/*     */   public String getInstanceName() {
/*  52 */     return firstCharacterLowerCaseConverter.convert(getInterfaceName());
/*     */   }
/*     */ 
/*     */   public String getInterfaceFullPackageName() {
/*  56 */     return this.entity.getPackageName() + ".dao";
/*     */   }
/*     */ 
/*     */   public String getClassFullPackageName() {
/*  60 */     return this.entity.getPackageName() + ".dao.ibatis";
/*     */   }
/*     */ 
/*     */   public List<String> getImportClassNameList(boolean concrete) {
/*  64 */     List list = new ArrayList();
/*     */     list.add("org.spring.BaseMapper");
/*  66 */     list.add(this.entity.getFullPackageName() + "." + this.entity.getClassName());
/*     */ 
/*  68 */     Criteria criteria = new Criteria(this.entity);
/*  69 */     //list.add(criteria.getFullPackageName() + "." + criteria.getClassName());
/*     */ 	
/*  71 */     list.add("java.util.List");
/*     */ 
/*  73 */     if ((concrete) && 
/*  74 */       ("Map".equals(getPrimaryKeyClassName()))) {
/*  75 */       list.add("java.util.Map");
/*  76 */       list.add("java.util.HashMap");
/*     */     }
/*     */ 
/*  80 */     list.add("org.springframework.dao.DataAccessException");
/*     */ 
/*  82 */     if (concrete) {
/*  83 */       list.add(getInterfaceFullPackageName() + "." + getInterfaceName());
/*  84 */       list.add("org.springframework.util.Assert");
/*  85 */       list.add("org.springframework.orm.ibatis.support.SqlMapClientDaoSupport");
/*  86 */       list.add(this.entity.getPackageName() + ".util.Paging");
/*  87 */       list.add(getInterfaceFullPackageName() + "." + getInterfaceName());
/*     */     }
/*     */ 
/*  90 */     if (this.entity.getPrimaryKeyFieldList() != null) {
/*  91 */       for (Field field : this.entity.getPrimaryKeyFieldList()) {
/*  92 */         if ((!field.isCreate()) || (field.getFieldType().indexOf('.') <= 0) || 
/*  93 */           (field.getFieldType().equals("java.lang." + field.getSimpleFieldType())) || 
/*  94 */           (list.contains(field.getFieldType()))) continue;
/*  95 */         list.add(field.getFieldType());
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 102 */     return list;
/*     */   }
/*     */ 
/*     */   public List<String> getImportDeclarations(boolean concrete) {
/* 106 */     List list = new ArrayList();
/* 107 */     list.addAll(getImportClassNameList(concrete));

/*     */ 
/* 109 */     String exceptPackageName = getInterfaceFullPackageName();
/* 110 */     if (concrete) {
/* 111 */       exceptPackageName = getClassFullPackageName();
/*     */     }
/*     */ 
/* 114 */     return ConventionUtils.getImportDeclarations(list, exceptPackageName);
/*     */   }
/*     */ 
/*     */   public String getToPrimitiveOpen() {
/* 118 */     if (this.entity.getPrimaryKeyFieldList().size() == 1) {
/* 119 */       Field field = (Field)this.entity.getPrimaryKeyFieldList().get(0);
/*     */ 
/* 121 */       if (field.isPrimitiveType()) {
/* 122 */         return "(";
/*     */       }
/*     */     }
/*     */ 
/* 126 */     return "";
/*     */   }
/*     */ 
/*     */   public String getToPrimitiveClose() {
/* 130 */     if (this.entity.getPrimaryKeyFieldList().size() == 1) {
/* 131 */       Field field = (Field)this.entity.getPrimaryKeyFieldList().get(0);
/*     */ 
/* 133 */       if (field.isPrimitiveType()) {
/* 134 */         return "." + field.getToPrimitiveMethod();
/*     */       }
/*     */     }
/*     */ 
/* 138 */     return "";
/*     */   }
/*     */ 
/*     */   public String getPrimaryKeyParameters() {
/* 142 */     return getPrimaryKeyParameters(true);
/*     */   }
/*     */ 
/*     */   public String getPrimaryKeyParameters(boolean includeType) {
/* 146 */     StringBuffer buffer = new StringBuffer();
/*     */ 
/* 148 */     for (Field field : this.entity.getPrimaryKeyFieldList()) {
/* 149 */       if (buffer.length() > 0) {
/* 150 */         buffer.append(", ");
/*     */       }
/*     */ 
/* 153 */       if (includeType) {
/* 154 */         buffer.append(field.getSimpleFieldType() + " ");
/*     */       }
/*     */ 
/* 157 */       buffer.append(field.getFieldName());
/*     */     }
/*     */ 
/* 160 */     return buffer.toString();
/*     */   }
/*     */ 
/*     */   public String getPrimaryKeyClassName() {
/* 164 */     if (this.entity.getPrimaryKeyFieldList().size() == 1) {
/* 165 */       Field field = (Field)this.entity.getPrimaryKeyFieldList().get(0);
/*     */ 
/* 167 */       return field.getSimpleObjectClassName();
/*     */     }
/*     */ 
/* 170 */     if (this.entity.getPrimaryKeyFieldList().size() > 1) {
/* 171 */       return "Map";
/*     */     }
/*     */ 
/* 174 */     return "FIXME:";
/*     */   }
/*     */ 
/*     */   public String getPrimaryKeySnippet() {
/* 178 */     return getPrimaryKeySnippet("\t\t");
/*     */   }
/*     */ 
/*     */   public String getPrimaryKeySnippet(String indent) {
/* 182 */     StringBuffer buffer = new StringBuffer();
/*     */ 
/* 184 */     if ("Map".equals(getPrimaryKeyClassName())) {
/* 185 */       buffer.append(indent + "Map<String, Object> param = new HashMap<String, Object>(" + this.entity.getPrimaryKeyFieldList().size() + ");" + FileUtils.ln());
/*     */ 
/* 187 */       for (Field field : this.entity.getPrimaryKeyFieldList()) {
/* 188 */         buffer.append(indent + "param.put(\"" + field.getFieldName() + "\", " + getInlineWrapperInstance(field) + ");" + FileUtils.ln());
/*     */       }
/*     */     }
/*     */ 
/* 192 */     return buffer.toString();
/*     */   }
/*     */ 
/*     */   public String getParameterVariableName() {
/* 196 */     if (this.entity.getPrimaryKeyFieldList().size() == 1) {
/* 197 */       Field field = (Field)this.entity.getPrimaryKeyFieldList().get(0);
/*     */ 
/* 199 */       return getInlineWrapperInstance(field);
/*     */     }
/*     */ 
/* 202 */     if (this.entity.getPrimaryKeyFieldList().size() >= 1) {
/* 203 */       return "param";
/*     */     }
/*     */ 
/* 206 */     return "FIXME:";
/*     */   }
/*     */ 
/*     */   public String getInlineWrapperInstance(Field field) {
/* 210 */     if (field.isPrimitiveType()) {
/* 211 */       return "new " + field.getSimpleObjectClassName() + "(" + field.getFieldName() + ")";
/*     */     }
/*     */ 
/* 214 */     return field.getFieldName();
/*     */   }
/*     */ 
/*     */   public Entity getEntity() {
/* 218 */     return this.entity;
/*     */   }
/*     */ 
/*     */   public void setEntity(Entity entity) {
/* 222 */     this.entity = entity;
/*     */   }
/*     */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.model.Dao
 * JD-Core Version:    0.6.0
 */